import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';

class IconDemo extends StatefulWidget {
  @override
  _IconDemoState createState() => _IconDemoState();
}

class _IconDemoState extends State<IconDemo> {
  @override
  Widget build(BuildContext context) {
    return Row(
      mainAxisAlignment: MainAxisAlignment.spaceEvenly,
      children: <Widget>[
        ActionButton(
          title: '相机',
          icon: Icons.camera_enhance,
          // image: AssetImage(''),
        ),
        ActionButton(
          title: '手写',
          icon: CupertinoIcons.pencil_slash,
          // image: AssetImage(''),
        ),
        ActionButton(
          title: '对话',
          icon: Icons.dialer_sip_outlined,
          // image: AssetImage(''),
        ),
        ActionButton(
          title: '语音',
          icon: Icons.mic,
          // image: AssetImage(''),
        ),
        Container(
          height: 60.0,
        )
      ],
    );
  }
}

class ActionButton extends StatefulWidget {
  final String title;
  final IconData icon;
  final AssetImage image;

  ActionButton({Key key, @required this.title, this.icon, this.image})
      : super(key: key);

  @override
  _ActionButtonState createState() => _ActionButtonState();
}

class _ActionButtonState extends State<ActionButton> {
  @override
  Widget build(BuildContext context) {
    return FlatButton(
      onPressed: () {},
      padding: EdgeInsets.only(left: 10.0, right: 10.0, top: 2.0, bottom: 12.0),
      child: Column(
        children: [
          _displayIcon(),
          Text(
            widget.title,
            style: TextStyle(color: Colors.black, fontSize: 16.0),
          ),
        ],
      ),
    );
  }

  Widget _displayIcon() {
    if (widget.icon != null) {
      return Icon(
        widget.icon,
        color: Color(0xff3f51B5),
        size: 26.0,
      );
    }else if(widget.image !=null){
      return ImageIcon(
        widget.image,
        size: 26.0,
        color: Color(0xff3f51B5),
      );
    } else {
      return Container(

      );
    }
  }
}
